Skip to content

Add persistent configuration storage#13

Merged
forketyfork merged 3 commits into
mainfrom
persistent-settings
Jan 2, 2026
Merged

Add persistent configuration storage#13
forketyfork merged 3 commits into
mainfrom
persistent-settings

Conversation

@forketyfork
Copy link
Copy Markdown
Owner

This PR implements persistent configuration storage for Architect, allowing user preferences to be remembered across application restarts.

Changes

New Configuration Module (src/config.zig)

  • Created Config struct that stores:
    • font_size: Selected font size
    • window_width and window_height: Window dimensions
    • window_x and window_y: Window position
  • Implements load() and save() methods for reading/writing JSON config
  • Configuration file location: ~/.config/architect/config.json
  • Includes test coverage for save/load functionality

Updated Main Application (src/main.zig)

  • Loads configuration on startup, falls back to defaults if not found
  • Automatically saves settings when:
    • Window is resized
    • Window is moved
    • Font size is changed (Cmd+Plus/Minus)
  • Restores window position on launch

Updated C Bindings (src/c.zig)

  • Added SDL_SetWindowPosition function
  • Added SDL_EVENT_WINDOW_MOVED event constant

Configuration File Format

{
  "font_size": 14,
  "window_width": 1200,
  "window_height": 900,
  "window_x": 150,
  "window_y": 100
}

Testing

All tests pass:

zig build test
zig build

The configuration directory is created automatically if it doesn't exist.

Prompt: I'd like the app to store its settings (selected font size and window size) in the configuration file located at ~/.config/architect. Could we also store the window position?

Solution: Implemented a configuration system that persists user preferences across application restarts:

- Created config.zig module with Config struct that stores font_size, window_width, window_height, window_x, and window_y
- Configuration is saved to ~/.config/architect/config.json in JSON format with proper indentation
- On startup, the application loads saved settings or falls back to defaults
- Settings are automatically saved when:
  - Window is resized (SDL_EVENT_WINDOW_RESIZED)
  - Window is moved (SDL_EVENT_WINDOW_MOVED)
  - Font size is changed via Cmd+Plus/Minus shortcuts
- Added SDL_SetWindowPosition and SDL_EVENT_WINDOW_MOVED to c.zig bindings
- Window position is restored on launch if previously saved (skipped if position is 0,0 to allow default centering on first run)

The configuration file uses a simple JSON structure and is created automatically in ~/.config/architect/ directory if it doesn't exist.
@forketyfork forketyfork requested a review from Copilot January 2, 2026 06:48
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds persistent configuration storage to Architect, enabling the application to remember user preferences like font size and window dimensions across sessions. The configuration is stored in JSON format at ~/.config/architect/config.json.

Key Changes:

  • New Config module with JSON-based persistence for font size and window geometry
  • Automatic configuration saving on window resize, move, and font size changes
  • Configuration restoration on application startup with fallback to defaults

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/config.zig Implements Config struct with load/save methods for JSON persistence and includes test coverage
src/main.zig Integrates config loading at startup, auto-saves on window/font changes, and restores window position
src/c.zig Adds SDL window positioning function and moved event constant

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/config.zig Outdated
Comment thread src/main.zig Outdated
Comment thread src/main.zig
Fixes based on Copilot review comments:

1. Fix fs.cwd().writeFile() usage with absolute path
   - Changed to use fs.createFileAbsolute() instead
   - The sub_path parameter expects relative paths, not absolute

2. Use sentinel value for window position
   - Changed default from (0, 0) to (-1, -1) as sentinel
   - Now correctly handles positions at (0, 0) and negative coordinates
   - Allows proper multi-monitor support

3. Reduce excessive I/O on window move
   - Removed auto-save on every SDL_EVENT_WINDOW_MOVED event
   - Window position is tracked but only saved on resize/font change
   - Prevents unnecessary file writes during window dragging

Updated documentation to reflect these changes.
@forketyfork forketyfork merged commit 9b23701 into main Jan 2, 2026
4 checks passed
@forketyfork forketyfork deleted the persistent-settings branch January 2, 2026 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants